﻿// JScript 文件


var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;
var mouseX=0;
var mouseY=0;

function setNodeType(obj,type){
	var c=obj.parentNode;
	var s=c.getElementsByTagName("span");
	var t={leaf:{style:"clsLeaf",text:"."},open:{style:"clsExpand",text:"-"},close:{style:"clsCollapse",text:"+"}}
	var o=null;
	if (s&&s[0]){
		o=s[0];
	}
	else{
		var o=document.createElement("span");
		c.insertBefore(o,obj);
	}
	o.innerHTML=t[type]["text"];
	o.className=t[type]["style"];
}
//获取鼠标位置
function moveToMouseLoc(e){
  if(ns4||ns6){
    mouseX = e.pageX;
    mouseY = e.pageY;
  }
  else{
    mouseX = event.x + document.body.scrollLeft;
    mouseY = event.y + document.documentElement.scrollTop;
  }
  return true;
}

//初始化菜单
//opened:true,默认展开,false,默认收起
function initNav(obj,opened){
	if(ns4) document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = moveToMouseLoc;
	var nav=document.getElementById(obj);
	var navItems=nav.getElementsByTagName("li");
	for (var i=0,c;c=navItems[i];i++){
		var t=c.getElementsByTagName("ul");
		var a=c.getElementsByTagName("a")[0];
		if (t.length==0){
			setNodeType(a,"leaf")
			a.onmouseout=function(){
				var tipDiv=this.parentNode.getElementsByTagName("div")[0];
				if (tipDiv){
				  tipDiv.style.display='none';
				}
			};
		}
		else{
			for (var j=0;j<t.length ;j++ ){
	          t[j].style.display='none';
			}
		setNodeType(a,opened?"open":"close");
		a.onfocus=function(){this.blur();return true;}
			a.onmouseup=function(){
				var t,p;
		        p=this.parentNode;
				var t=p.getElementsByTagName("ul")[0];

				if (t.style.display=='none'){
					setNodeType(this,"open");
					t.style.display='';
				}
				else{
					setNodeType(this,"close");
					t.style.display='none';
				}
				return false;
			};
			//设置菜单的样式
			a.onmouseover=function(){
				var t=this.parentNode.getElementsByTagName("ul")[0];
			};
			//设置菜单的样式
			a.onmouseout=function(){
				var t=this.parentNode.getElementsByTagName("ul")[0];
				var tipDiv=this.parentNode.getElementsByTagName("div")[0];
				if (tipDiv){
				  tipDiv.style.display='none';
				}
			};
			//设置菜单提示
			a.onmousemove=function(){
			  var tipDiv=this.parentNode.getElementsByTagName("div")[0];
			  if (tipDiv){
				with (tipDiv.style){
				  display='block';
				  left=parseInt(mouseX)+"px";
				  top=(parseInt(mouseY)+20)+"px";
				  position='absolute';
				}
			  }
			}
		}
	}
}